package com.ld.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author: Liudao
 * @Date: 2022-08-17-15:01
 * @Description:
 */
@ControllerAdvice//这相当于是个组件放到容器中
public class MyExceptionHandler {

    //处理自定义异常
    @ExceptionHandler(MyException.class)
    public String aa(Model model,Exception aa){
        //定义异常信息
        String info = "";
        //判断异常类型
        if (aa instanceof MyException){
            info = ((MyException) aa).getMm();
        }
        //将异常信息放到model中
        model.addAttribute("info",info);
        return "error/errorv";
    }

    //处理一般异常
    @ExceptionHandler(Exception.class)
    public String bb(Model model){
        model.addAttribute("info","有异常出现了");
        return "error/errorv";
    }



}
